#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    bool isprime(int n)
    {
        if (n == 1) return false;
        if (n > 1)
        {
            for (int i = 2; i <= sqrt(n); i++)
            {
                if (n % i == 0)
                    return false;
            }
        }
        return true;
    }

    int maximumPrimeDifference(vector<int>& nums)
    {
        for (int i = 0; i < nums.size(); i++)
        {
            if (isprime(nums[i]))
                nums[i] = 1;
            else
                nums[i] = 0;
        }
        return (nums.size() - (find(nums.rbegin(), nums.rend(), 1) - nums.rbegin()) - 1) - (find(nums.begin(), nums.end(), 1) - nums.begin());
    }
};